package com.bsoft.gol.hcs.his.service.impl;

import com.bsoft.gol.hcs.clinical.bean.req.*;
import com.bsoft.gol.hcs.clinical.bean.req.inspectionreq.*;
import com.bsoft.gol.hcs.clinical.bean.req.inspectionreq.Visit;
import com.bsoft.gol.hcs.clinical.bean.response.*;
import com.bsoft.gol.hcs.clinical.bean.response.inspectionResq.*;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import hcn.util.BaseResponse;
import hcn.util.ResultCode;
import com.bsoft.gol.hcs.his.service.IInspectionHisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.bsoft.gol.hcs.utils.BaseRespUtil;
import com.bsoft.gol.hcs.utils.CommonUtils;
import com.bsoft.gol.hcs.utils.Constants;
import org.atag.util.http.KdHttpClientUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static com.alibaba.fastjson.JSON.toJSONString;

/**
 * @Description: 检验his服务
 * @Author: zhaorb
 * @Date: 2020/6/4 15:08
 **/
@Service
public class InspectionHisService implements IInspectionHisService {
    private final static Logger log = LoggerFactory.getLogger(InspectionHisService.class);

    private static String url = "http://10.8.3.125:8070/labPlatInterface/appServlet";
        /**
     * 获取检验申请单类别和项目
     * @param req
     * @return
     */
    @Override
    public BaseResponse<List<QueryInspectionItemListResp>> queryInspectionItemList(QueryInspectionItemListReq req) {
        log.info("queryInspectionItemList-入参=>>>" + req.toString() + "=====");
        QueryInspectionItemListNewReq queryInspectionItemListNewReq =   this.transFormReq(req);
        JSONObject jsonParams = JSONObject.parseObject(toJSONString(queryInspectionItemListNewReq));
        JSONObject jsonObject = KdHttpClientUtil.doMainPost(Constants.HIS_CLIENT_URL_01
                , new Object[]{Constants.QUERY_INSPECTION_ITEM_LIST, "", "", jsonParams});
        try {
            if (jsonObject.getInteger("code") == ResultCode.SUCCESS) {
                List<QueryInspectionItemListNewResp> resps = JSONObject.parseArray(
                        jsonObject.getJSONArray("data").toJSONString(), QueryInspectionItemListNewResp.class);
                List<QueryInspectionItemListResp>  list = this.transFormResqD0(resps);
                return BaseRespUtil.setResultSuccess(list);
            } else {
                return BaseRespUtil.setResultError(jsonObject.getString("message"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
            return BaseRespUtil.setResultError(Constants.JSON_ANALYSIS_ERR + e.getMessage());
        }
    }


    //入参转化
    public QueryInspectionItemListNewReq transFormReq(QueryInspectionItemListReq req){
        QueryInspectionItemListNewReq queryInspectionItemListReq = new QueryInspectionItemListNewReq();
        queryInspectionItemListReq.setVisitOrganization(req.getOrganizationId());
        queryInspectionItemListReq.setRequestDept(req.getDepartmentId());
        queryInspectionItemListReq.setRequestDoctor(req.getDoctorId());
        queryInspectionItemListReq.setPatientType(req.getSource());
        queryInspectionItemListReq.setPinYinCode(req.getPinYinCode());
        return queryInspectionItemListReq;
    }

    //出参转化
    public List<QueryInspectionItemListResp> transFormResqD0(List<QueryInspectionItemListNewResp> list){
        List<QueryInspectionItemListResp> resps = new ArrayList<>();
        if(CommonUtils.isNotEmpty(list)){
            for (QueryInspectionItemListNewResp resp:list) {
                QueryInspectionItemListResp queryInspectionItemListResp = new QueryInspectionItemListResp();
                queryInspectionItemListResp.setInspectionTypeId(resp.getItemTypeCode());
                queryInspectionItemListResp.setInspectionTypeName(resp.getItemTypeName());
                List<InspectionItemResp> inspectionItemResps = new ArrayList<>();
                if(CommonUtils.isNotEmpty(resp.getItems().getItem()) && resp.getItems().getItem().size()>0){
                    for (InspectionItemNewResp inspectionItemNewResp :resp.getItems().getItem()) {
                        InspectionItemResp inspectionItemResp = new InspectionItemResp();
                        inspectionItemResp.setInspectionItemId(inspectionItemNewResp.getItemCode());
                        inspectionItemResp.setInspectionItemName(inspectionItemNewResp.getItemName());
                        inspectionItemResp.setIsCompose(inspectionItemNewResp.getComposeType());
                        inspectionItemResp.setIsEmergency(inspectionItemNewResp.getIsEmergency());
                        inspectionItemResp.setNumber(inspectionItemNewResp.getItemCount());
                        inspectionItemResp.setPrice(inspectionItemNewResp.getItemPrice());
                        inspectionItemResp.setPyCode(inspectionItemNewResp.getInputCode());
                        inspectionItemResps.add(inspectionItemResp);
                    }
                }
                queryInspectionItemListResp.setInspectionTypeList(inspectionItemResps);
                resps.add(queryInspectionItemListResp);
            }
        }
        return resps;
    }

    /**
     * 2、获取检验申请单子项目明细
     * @param req
     * @return
     */
    @Override
    public BaseResponse<List<QueryInspectionItemDtailResp>> queryInspectionItemDtail(QueryInspectionItemDtailReq req) {
        log.info("queryInspectionItemDtail-入参=>>>" + req.toString() + "=====");
        QueryInspectionItemDtailNewReq req1 = this.transFormReq(req);
        JSONObject jsonParams = JSONObject.parseObject(toJSONString(req));
        JSONObject jsonObject = KdHttpClientUtil.doMainPost(Constants.HIS_CLIENT_URL_01
                , new Object[]{Constants.QUERY_INSPECTION_ITEM_DTAIL, "", "", jsonParams});
        try {
            if (jsonObject.getInteger("code") == ResultCode.SUCCESS) {
                List<QueryInspectionItemDtailNewResp> resps = JSONObject.parseArray(
                        jsonObject.getJSONArray("data").toJSONString(), QueryInspectionItemDtailNewResp.class);
                List<QueryInspectionItemDtailResp> list = this.transFormResqD1(resps);
                return BaseRespUtil.setResultSuccess(list);
            } else {
                return BaseRespUtil.setResultError(jsonObject.getString("message"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
            return BaseRespUtil.setResultError(Constants.JSON_ANALYSIS_ERR + e.getMessage());
        }
    }


    //入参转化
    public QueryInspectionItemDtailNewReq transFormReq(QueryInspectionItemDtailReq req){
        QueryInspectionItemDtailNewReq queryInspectionItemListReq = new QueryInspectionItemDtailNewReq();
        queryInspectionItemListReq.setVisitOrganization(req.getOrganizationId());
        queryInspectionItemListReq.setItemCode(req.getInspectionItemId());
        return queryInspectionItemListReq;
    }

    //出参转化
    public List<QueryInspectionItemDtailResp> transFormResqD1(List<QueryInspectionItemDtailNewResp> list){
        List<QueryInspectionItemDtailResp> resps = new ArrayList<>();
        if(CommonUtils.isNotEmpty(list)){
            for (QueryInspectionItemDtailNewResp resp:list) {
                QueryInspectionItemDtailResp queryInspectionItemListResp = new QueryInspectionItemDtailResp();
                queryInspectionItemListResp.setExecuteDepartmentId(resp.getExamExecuteDept());
                queryInspectionItemListResp.setExecuteDepartmentName(resp.getExamExecuteDeptName());
                queryInspectionItemListResp.setInspectionItemId(resp.getItemCode());
                queryInspectionItemListResp.setInspectionItemName(resp.getItemName());
                queryInspectionItemListResp.setNumber(resp.getItemCount());
                queryInspectionItemListResp.setPrice(resp.getItemPrice());
                List<ExpenseItemResp> inspectionItemResps = new ArrayList<>();
                if(CommonUtils.isNotEmpty(resp.getItemlists().getItemlist()) && resp.getItemlists().getItemlist().size()>0){
                    for (ExpenseItemNewResp inspectionItemNewResp :resp.getItemlists().getItemlist()) {
                        ExpenseItemResp expenseItemResp = new ExpenseItemResp();
                        expenseItemResp.setItemId(inspectionItemNewResp.getCostId());
                        expenseItemResp.setItemName(inspectionItemNewResp.getCostName());
                        expenseItemResp.setNumber(inspectionItemNewResp.getCostNumber());
                        expenseItemResp.setPrice(inspectionItemNewResp.getCostPrice());
                        expenseItemResp.setInspectionItemDetailId(inspectionItemNewResp.getChildItemCode());
                        expenseItemResp.setInspectionItemDetailName(inspectionItemNewResp.getChildItemName());
                        inspectionItemResps.add(expenseItemResp);
                    }
                }
                queryInspectionItemListResp.setItemList(inspectionItemResps);
                resps.add(queryInspectionItemListResp);
            }
        }
        return resps;
    }

    /**
     * 3、获取样本类型
     * @param request
     * @return
     */
    @Override
    public BaseResponse<List<QuerySampleTypeResp>> querySampleType(QuerySampleTypeReq request) {
        log.info("querySampleType-入参=>>>" + request.toString() + "=====");
        BaseResponse result = new BaseResponse();
        QueryInspectionItemDtailNewReq req = this.transFormReq(request);
        JSONObject jsonParams = JSONObject.parseObject(toJSONString(request));
        JSONObject jsonObject = KdHttpClientUtil.doMainPost(Constants.HIS_CLIENT_URL_01
                ,  new Object[]{Constants.QUERY_SPECIMEN_LIST, "","", jsonParams});
        log.info("querySampleType第三方返回数据:{}", result);
        try {
            if (jsonObject.getInteger("code") == ResultCode.SUCCESS && jsonObject.containsKey("data") &&
                    jsonObject.get("data") != null) {
                List<QuerySampleTypeNewResp> resps = JSONObject.parseArray(
                        jsonObject.getJSONArray("data").toJSONString(), QuerySampleTypeNewResp.class);
                List<QuerySampleTypeResp> list = this.transFormResqD2(resps);
                result.setData(list);
            } else {
                return BaseRespUtil.setResultError(jsonObject.getString("message"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
            return BaseRespUtil.setResultError(Constants.JSON_ANALYSIS_ERR + e.getMessage());
        }
        return result;
    }

    //入参转化
    public QueryInspectionItemDtailNewReq transFormReq(QuerySampleTypeReq req){
        QueryInspectionItemDtailNewReq queryInspectionItemListReq = new QueryInspectionItemDtailNewReq();
        queryInspectionItemListReq.setVisitOrganization(req.getOrganizationId());
        queryInspectionItemListReq.setItemCode(req.getInspectionItemId());
        return queryInspectionItemListReq;
    }

    //出参转化
    public List<QuerySampleTypeResp> transFormResqD2(List<QuerySampleTypeNewResp> list){
        List<QuerySampleTypeResp> resps = new ArrayList<>();
        if(CommonUtils.isNotEmpty(list)){
            for (QuerySampleTypeNewResp resp:list) {
                QuerySampleTypeResp querySampleTypeResp = new QuerySampleTypeResp();
                querySampleTypeResp.setSpecimenTypeId(resp.getSampleTypeCode());
                querySampleTypeResp.setSpecimenTypeName(resp.getSampleTypeName());
                resps.add(querySampleTypeResp);
            }
        }
        return resps;
    }



    /**
     * @Description: 获得检验申请单号
     * @Author: zhaorb
     * @Date: 2020/6/6 14:55
     **/
    @Override
    public BaseResponse<List<ApplyNoResponse>>  queryInspectionApplyNo(ApplyNoRequest request) {
        BaseResponse<List<ApplyNoResponse>> response = new BaseResponse<>();
        List<ApplyNoResponse> result = new ArrayList<>();
        ApplyNoNewRequest applyNoNewRequest = this.transFormReq(request);
        JSONObject jsonParams = JSONObject.parseObject(toJSONString(applyNoNewRequest));
        JSONObject jsonObject = KdHttpClientUtil.doMainPost(Constants.HIS_CLIENT_URL_01
                , new Object[]{Constants.QUERY_INSPECTION_APPLY_NO, "","",jsonParams});
        log.info("queryCheckPositionList:{}", result);
        try {
            if (jsonObject.getInteger("code") == ResultCode.SUCCESS && jsonObject.containsKey("data") &&
                    jsonObject.get("data") != null) {
                List<ApplyNoNewResponse> resp = JSONObject.parseArray(
                        jsonObject.getJSONArray("data").toJSONString(), ApplyNoNewResponse.class);
                List<ApplyNoResponse> responses = this.transFormResqD3(resp);
                response.setData(responses);
                return response;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }


    //入参转化
    public ApplyNoNewRequest transFormReq(ApplyNoRequest req){
        ApplyNoNewRequest applyNoNewRequest = new ApplyNoNewRequest();
        applyNoNewRequest.setVisitOrganization(req.getOrganizationId());
        applyNoNewRequest.setRecordCount(req.getCount());
        return applyNoNewRequest;
    }

    //出参转化
    public List<ApplyNoResponse> transFormResqD3(List<ApplyNoNewResponse> list){
        List<ApplyNoResponse> resps = new ArrayList<>();
        if(CommonUtils.isNotEmpty(list)){
            for (ApplyNoNewResponse resp:list) {
                ApplyNoResponse querySampleTypeResp = new ApplyNoResponse();
                querySampleTypeResp.setApplicationNo(resp.getRequestId());
                resps.add(querySampleTypeResp);
            }
        }
        return resps;
    }


    /**
     * 提交申请单
     * @param req
     * @return
     */
    @Override
    public BaseResponse<SaveInspectionInfoResp> saveInspectionInfo(SaveInspectionInfoReq req) {
        log.info("saveInspectionInfo-入参=>>>" + req.toString() + "=====");
        BaseResponse<SaveInspectionInfoResp> response = new BaseResponse<>();
        SaveInspectionInfoNewReq saveInspectionInfoNewReq = this.transFormReq(req);
        JSONObject jsonParams = JSONObject.parseObject(toJSONString(saveInspectionInfoNewReq));
        JSONObject jsonObject = KdHttpClientUtil.doMainPost(Constants.HIS_CLIENT_URL_01
                , new Object[]{Constants.SAVE_INSPECTION_INFO, "", "", jsonParams});
        try {
            if (jsonObject.getInteger("code") == ResultCode.SUCCESS) {
                SaveInspectionInfoNewResp resp = JSONObject.parseObject(
                        jsonObject.getJSONObject("data").toJSONString(), SaveInspectionInfoNewResp.class);
                SaveInspectionInfoResp saveInspectionInfoResp =  transFormResqD4(resp);
                log.info("saveInspectionInfo-出参=>>>" + resp.toString() + "=====");
                response.setCode(jsonObject.getInteger("code"));
                response.setMessage(jsonObject.getString("message"));
                response.setData(saveInspectionInfoResp);
                return response;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return response;
    }


    //入参转化
    public SaveInspectionInfoNewReq transFormReq(SaveInspectionInfoReq req){
        SaveInspectionInfoNewReq saveInspectionInfoNewReq = new SaveInspectionInfoNewReq();
        //患者信息
        PatientHis patient = new PatientHis();
        patient.setSourcePatientId(req.getPatientId());
        patient.setSourcePatientIdType(req.getSourcePatientIdType());//todo
        patient.setAuthorOrganization(req.getOrganizationId());//todo
        patient.setIdCard(req.getCardNumber());
        patient.setIdCardCode(req.getCardType());
        patient.setName(req.getPatientName());
        patient.setSex(req.getSex());
        patient.setSexName( null == req.getSexName()?"":req.getSexName());
        patient.setBirthDate(req.getBirthday());
        patient.setPatientPhone(req.getTelephone());
        patient.setPatientProperties("1000");
        patient.setAddress(req.getAddress());
        saveInspectionInfoNewReq.setPatient(patient);

        //就诊摘要
        Visit visit = new Visit();
        visit.setVisitId(req.getInHospitalRecordCode());
        visit.setVisitOrganization(req.getOrganizationId());
        visit.setPatientType(req.getSource());
        visit.setPatientTypeName("");
        visit.setMedicalCardId(req.getPatientMedicalCardNumber());
        visit.setMedicalCardType(req.getPatientMedicalCardType());
        visit.setClinicId("");
        visit.setHospizationId("");
//        visit.setPatientProperties("1000");
//        visit.setPatientProperties(req.getPatientProperties());
        visit.setPatientPhone("");
        visit.setAddress("");
        saveInspectionInfoNewReq.setVisit(visit);
        //申请单

        ExamineDetailReq examineDetailReq = req.getApplicationlist();
        LabRequest labRequest = new LabRequest();
        labRequest.setRequestId(examineDetailReq.getApplicationNo());
        labRequest.setIsNeonatus(examineDetailReq.getIsNeonatus());//todo
        labRequest.setAge(String.valueOf(examineDetailReq.getAge()));//todo
        labRequest.setMonthAge("");
        labRequest.setWardArea("");
        labRequest.setWardAreaName("");
        labRequest.setSickbedId("");
        labRequest.setSickRoomId("");
        labRequest.setSickRoomNo("");
        labRequest.setSickbedNo("");
        labRequest.setIsEmergency(examineDetailReq.getIsEmergency());
        labRequest.setRequestModeName("");
        labRequest.setRequestDateTime(null == examineDetailReq.getApplyTime()?"":examineDetailReq.getApplyTime());
        labRequest.setEffectiveTimeLow(null == examineDetailReq.getEffectiveTimeLow()?"":examineDetailReq.getEffectiveTimeLow());//todo
        labRequest.setEffectiveTimeHigh(null == examineDetailReq.getEffectiveTimeHigh()?"":examineDetailReq.getEffectiveTimeHigh());//todo
        labRequest.setRequestDoctor(examineDetailReq.getApplyDoctorId());
        labRequest.setRequestDoctorName(examineDetailReq.getApplyDoctorName());
        labRequest.setRequestDept(examineDetailReq.getApplyDepartmentId());
        labRequest.setRequestDeptName(examineDetailReq.getApplyDepartmentName());
        labRequest.setRequestCheckerId(null == examineDetailReq.getRequestCheckerId()?"":examineDetailReq.getRequestCheckerId());//todo
        labRequest.setRequestCheckerName(null == examineDetailReq.getRequestCheckerName()?"":examineDetailReq.getRequestCheckerName());//todo
        labRequest.setRequestCheckTime(null == examineDetailReq.getRequestCheckTime()?"":examineDetailReq.getRequestCheckTime());//todo
        labRequest.setExamText("");
        labRequest.setExamExecuteOrg("");
        labRequest.setRequestStatus(examineDetailReq.getRequestStatus());//todo
        labRequest.setDept(examineDetailReq.getDepartmentId());
        labRequest.setDeptName(examineDetailReq.getDepartmentName());
        labRequest.setRemarkInfo("");
        //诊断
        List<Diagnose> diagnoses = new ArrayList<>();
        List<DiagnosisReq> diagnosisReqs = examineDetailReq.getDiagnosisReqList();
        if(CommonUtils.isNotEmpty(diagnosisReqs)){
            for (DiagnosisReq diagnosisReq: diagnosisReqs) {
                Diagnose diagnose = new Diagnose();
                diagnose.setDiagnoseTypeCode(diagnosisReq.getDiagnosisType());
                diagnose.setDiagnoseTypeName(diagnosisReq.getDiseasesName());
                diagnose.setDiagnoseCode(diagnosisReq.getDiseasesId());
                diagnose.setDiagnoseName("");
                diagnose.setDiagnoseDateTime("");
                diagnoses.add(diagnose);
            }
        }

        LabRequest.Diagnoses diagnoses1 = new LabRequest.Diagnoses();
        diagnoses1.setDiagnose(diagnoses);
        labRequest.setDiagnoses(diagnoses1);

        //检验申请项目
        List<Item> items = new ArrayList<>();
        List<InspectionItemDetail> inspectionItemDetails = examineDetailReq.getInspectionItemDetailList();
        if(CommonUtils.isNotEmpty(inspectionItemDetails)){
            for (InspectionItemDetail itemDetail:inspectionItemDetails) {
                Item item = new Item();
                item.setOrderId("1");
//                item.setOrderId(null == itemDetail.getExpenseId()?"":itemDetail.getExpenseId());
                item.setBarcodeNo(null == itemDetail.getBarcodeNo()?"":itemDetail.getBarcodeNo());
                item.setItemCode(null == itemDetail.getInspectionItemId()?"":itemDetail.getInspectionItemId());
                item.setItemName(null == itemDetail.getInspectionItemName()?"":itemDetail.getInspectionItemName());
                item.setSampleTypeCode(null == itemDetail.getSpecimenTypeId()?"":itemDetail.getSpecimenTypeId());
                item.setSampleTypeName(null == itemDetail.getSpecimenTypeName()?"":itemDetail.getSpecimenTypeName());
                item.setItemPrice(itemDetail.getPrice());
                item.setItemCount(itemDetail.getNumber());
                item.setItemCost(itemDetail.getItemCost());
                item.setFeeStatus(itemDetail.getFeeStatus());//todo
                item.setCostFreeSign(itemDetail.getIsFree());
                item.setExamExecuteDept(null == itemDetail.getExecuteDepartmentId()?"":itemDetail.getExecuteDepartmentId());
                item.setExamExecuteDeptName(null == itemDetail.getExecuteDepartmentName()?"":itemDetail.getExecuteDepartmentName());
                item.setExamExecuteTime("");
                item.setRequestNote("");
                item.setInvoiceNo("");
                item.setExamMethodCode("");
                item.setExamMethodName("");
                item.setFeetype(itemDetail.getFeeType());

                List<Childitem> childitems = new ArrayList<>();
                if(CommonUtils.isNotEmpty(itemDetail.getItemList())){
                    for (ItemDetail detail :itemDetail.getItemList()) {
                        Childitem childitem = new Childitem();
                        childitem.setChildItemCode(null == detail.getInspectionItemDetailId()?"":detail.getInspectionItemDetailId());
                        childitem.setChildItemName(null == detail.getInspectionItemDetailName()?"":detail.getInspectionItemDetailName());
                        childitem.setOrderDetailId(null == detail.getJlxh()?"":detail.getJlxh());
                        childitem.setOrderDetailId("2");
                        childitem.setCostId(detail.getItemId());
                        childitem.setCostName(detail.getItemName());
                        childitem.setCostPrice(detail.getPrice());
                        childitem.setCostNumber(detail.getNumber());
                        childitems.add(childitem);
                    }
                }

                Item.Childitems citems = new Item.Childitems();
                citems.setChilditem(childitems);
                item.setChilditems(citems);
                items.add(item);
            }
        }

        LabRequest.Items items1 = new LabRequest.Items();
        items1.setItem(items);
        labRequest.setItems(items1);
        saveInspectionInfoNewReq.setLabRequest(labRequest);
        return saveInspectionInfoNewReq;
    }

    //出参转化
    public SaveInspectionInfoResp transFormResqD4(SaveInspectionInfoNewResp newResp){
        SaveInspectionInfoResp resps = new SaveInspectionInfoResp();
        if(CommonUtils.isNotEmpty(newResp)){
            resps.setOrganizationId(newResp.getVisitOrganization());
            resps.setOrganizationName(newResp.getVisitOrganizationName());
            resps.setPatientId(newResp.getSourcePatientId());
            resps.setPatientName(newResp.getName());
            resps.setSex(newResp.getSex());
            resps.setCardType(newResp.getIdCardCode());
            resps.setCardNumber(newResp.getIdCard());
            resps.setPatientMedicalCardType(newResp.getMedicalCardType());
            resps.setPatientMedicalCardNumber(newResp.getMedicalCardId());
            resps.setEmergencyNumber(newResp.getVisitId());
            resps.setDepartmentId(newResp.getDept());
            resps.setDepartmentName(newResp.getDeptName());
            resps.setApplyDoctorId(newResp.getRequestDoctor());
            resps.setApplyDoctorName(newResp.getRequestDoctorName());
            resps.setApplyDepartmentId(newResp.getRequestDept());
            resps.setApplyDepartmentName(newResp.getRequestDeptName());
            ExpenseLabReq expenseLabReq = new ExpenseLabReq();
            ExpenseItemNewReq itemNewReq = newResp.getLabRequest();
            if(CommonUtils.isNotEmpty(itemNewReq)){
                expenseLabReq.setApplicationNo(itemNewReq.getRequestId());
                expenseLabReq.setApplyStatus(itemNewReq.getRequestStatus());
                expenseLabReq.setEmergencyTag(itemNewReq.getIsEmergency());

                List<Item> list = itemNewReq.getItems().getItem();
                List<ExpenseItemReq> expenseItemReqs = new ArrayList<>();
                if(CommonUtils.isNotEmpty(list)){
                    for (Item  item:list) {
                        ExpenseItemReq expenseItemReq = new ExpenseItemReq();
                        expenseItemReq.setExpenseId(item.getAdviceExpenseId());
                        expenseItemReq.setInspectionItemId(item.getItemCode());
                        expenseItemReq.setInspectionItemName(item.getItemName());
                        expenseItemReq.setSpecimenTypeId(item.getSampleTypeCode());
                        expenseItemReq.setSpecimenTypeName(item.getSampleTypeName());
                        expenseItemReq.setTotalAmount(item.getItemCost());
                        expenseItemReq.setChargeStatus(item.getFeeStatus());
                        expenseItemReq.setFeeType(item.getFeetype());

                        List<ExpenseDetailReq> expenseDetailReqs = new ArrayList<>();
                        List<Childitem> childitems = item.getChilditems().getChilditem();
                        if(CommonUtils.isNotEmpty(childitems)){
                            for (Childitem childitem: childitems) {
                                ExpenseDetailReq expenseDetailReq = new ExpenseDetailReq();
                                expenseDetailReq.setInspectionItemDetailId(childitem.getChildItemCode());
                                expenseDetailReq.setInspectionItemDetailName(childitem.getChildItemName());
                                expenseDetailReq.setExpenseDetailId(childitem.getAdviceExpenseDetailId());
                                expenseDetailReq.setItemId(childitem.getCostId());
                                expenseDetailReq.setItemName(childitem.getCostName());
                                expenseDetailReq.setNumber(childitem.getCostNumber());
                                expenseDetailReq.setPrice(childitem.getCostPrice());
                                expenseDetailReq.setUnit(childitem.getCostUnit());
                                expenseDetailReq.setAmount(childitem.getDetailCost());
                                expenseDetailReqs.add(expenseDetailReq);
                            }
                        }
                        expenseItemReq.setDetailList(expenseDetailReqs);
                        expenseItemReqs.add(expenseItemReq);
                    }

                }
                expenseLabReq.setItemReqList(expenseItemReqs);
            }

            resps.setList(expenseLabReq);
        }
        return resps;
    }


    /**
     * 撤销申请单
     * @param request
     * @return
     */

    @Override
    public BaseResponse cancelInspectionItem(CancelInspectionItemReq request) {
        log.info("=cancelInspectionItem-入参=>>>" + request.toString() + "=====");
        BaseResponse result = new BaseResponse();
        CancelInspectionItemNewReq cancelInspectionItemNewReq = this.transFormReq(request);
        JSONObject jsonParams = JSONObject.parseObject(toJSONString(cancelInspectionItemNewReq));
        JSONObject jsonObject = KdHttpClientUtil.doMainPost(Constants.HIS_CLIENT_URL_01
                ,  new Object[]{Constants.CANCEL_INSPECTION_ITEM, "","", jsonParams});
        log.info("cancelInspectionItem 第三方返回数据:{}", result);
        try {
            if (jsonObject.getInteger("code") == ResultCode.SUCCESS ) {
                result.setCode(jsonObject.getInteger("code"));
                result.setMessage(jsonObject.getString("message"));
            } else {
                return BaseRespUtil.setResultError(jsonObject.getString("message"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
            return BaseRespUtil.setResultError(Constants.JSON_ANALYSIS_ERR + e.getMessage());
        }
        return result;
    }

    //入参转化
    public CancelInspectionItemNewReq transFormReq(CancelInspectionItemReq req){
        CancelInspectionItemNewReq cancelInspectionItemNewReq = new CancelInspectionItemNewReq();
        cancelInspectionItemNewReq.setVisitOrganization(req.getOrganizationId());
        cancelInspectionItemNewReq.setConsultId(req.getConsultId());
        cancelInspectionItemNewReq.setOperatorId(req.getOperatorId());
        cancelInspectionItemNewReq.setOperatorName(req.getOperatorName());
        cancelInspectionItemNewReq.setRegisteredSerialNo(req.getRegisteredSerialNo());
        cancelInspectionItemNewReq.setRequestId(req.getApplicationNo());
        cancelInspectionItemNewReq.setOperateDateTime(req.getOperationTime());
        return cancelInspectionItemNewReq;
    }


    /**
     * 获取申请单项目附加费用
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse<QueryInspectionExtraFeeResp> queryInspectionExtraFee(QueryInspectionExtraFeeReq request) {
        log.info("=queryInspectionExtraFee-入参=>>>" + request.toString() + "=====");
        BaseResponse<QueryInspectionExtraFeeResp> result = new BaseResponse();
        QueryInspectionExtraFeeNewReq req = this.transFormReq(request);
        JSONObject jsonParams = JSONObject.parseObject(toJSONString(req));
        JSONObject jsonObject = KdHttpClientUtil.doMainPost(Constants.HIS_CLIENT_URL_01
                ,  new Object[]{Constants.QUERY_INSPECTION_EXTRA_FEE, "","", jsonParams});
        log.info("queryInspectionExtraFee 第三方返回数据:{}", result);
        try {
            if (jsonObject.getInteger("code") == ResultCode.SUCCESS && jsonObject.containsKey("data") &&
                    jsonObject.get("data") != null) {
                //出参转换开始
                QueryInspectionExtraFeeNewResp list = JSONObject.parseObject(
                        jsonObject.getJSONObject("data").toJSONString(), QueryInspectionExtraFeeNewResp.class);
                //出参转换结束
                QueryInspectionExtraFeeResp resp = this.transFormResqD6(list);
                result.setData(resp);
            } else {
                result.setCode(ResultCode.ERROR);
                result.setMessage(jsonObject.getString("message"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
            result.setCode(ResultCode.ERROR);
            result.setMessage(jsonObject.getString("message"));
        }
        return result;
    }


    //入参转化
    public QueryInspectionExtraFeeNewReq transFormReq(QueryInspectionExtraFeeReq req){
        QueryInspectionExtraFeeNewReq inspectionExtraFeeNewReq = new QueryInspectionExtraFeeNewReq();
        inspectionExtraFeeNewReq.setVisitOrganization(req.getOrganizationId());
        List<InspectionItemNew> Itemlists = new ArrayList<>();
        if(CommonUtils.isNotEmpty(req.getInspectionItemList())){
            for (InspectionItem inspectionItem:req.getInspectionItemList()) {
                InspectionItemNew inspectionItemNew = new InspectionItemNew();
                inspectionItemNew.setItemCode(inspectionItem.getInspectionItemId());
                inspectionItemNew.setItemName(inspectionItem.getInspectionItemName());
                inspectionItemNew.setRequestId(inspectionItem.getApplicationNo());
                inspectionItemNew.setSampleTypeCode(inspectionItem.getSpecimenTypeId());
                inspectionItemNew.setSampleTypeName(inspectionItem.getSpecimenTypeName());
                inspectionItemNew.setItemCount(inspectionItem.getNumber());
                Itemlists.add(inspectionItemNew);
            }
        }
        QueryInspectionExtraFeeNewReq.Itemlists itemlistsS = new QueryInspectionExtraFeeNewReq.Itemlists();
        itemlistsS.setItemlist(Itemlists);
        inspectionExtraFeeNewReq.setItemlists(itemlistsS);

        return inspectionExtraFeeNewReq;
    }

    //出参转化
    public QueryInspectionExtraFeeResp transFormResqD6(QueryInspectionExtraFeeNewResp list){
        QueryInspectionExtraFeeResp resps = new QueryInspectionExtraFeeResp();
        List<ExtraFee> extraFees = new ArrayList<>();
        if(CommonUtils.isNotEmpty(list.getItemlist())){
            for (ExtraFeeNew resp:list.getItemlist()) {
                ExtraFee extraFee = new ExtraFee();
                extraFee.setApplicationNo(resp.getRequestId());
                extraFee.setExecuteDepartmentId(resp.getExamExecuteDept());
                extraFee.setItemId(resp.getCostId());
                extraFee.setItemName(resp.getCostName());
                extraFee.setNumber(resp.getCostNumber());
                extraFee.setPrice(resp.getCostPrice());
                extraFees.add(extraFee);
            }
        }

        resps.setItemList(extraFees);
        return resps;
    }


    /**
     * 获取申请单注意通知
     * @param request
     * @return
     */
    @Override
    public BaseResponse<List<QueryInspectionNoticeResp>> queryInspectionNotice(QueryInspectionNoticeReq request) {
        log.info("=queryInspectionNotice-入参=>>>" + request.toString() + "=====");
        BaseResponse<List<QueryInspectionNoticeResp>> result = new BaseResponse();
        QueryInspectionExtraFeeNewReq req = this.transFormReq(request);
        JSONObject jsonParams = JSONObject.parseObject(toJSONString(req));
        JSONObject jsonObject = KdHttpClientUtil.doMainPost(Constants.HIS_CLIENT_URL_01
                ,  new Object[]{Constants.QUERY_INSPECTION_NOTICE, "","", jsonParams});
        log.info("queryInspectionNotice 第三方返回数据:{}", result);
        try {
            if (jsonObject.getInteger("code") == ResultCode.SUCCESS && jsonObject.containsKey("data") &&
                    jsonObject.get("data") != null) {
                //出参转换开始
                List<QueryInspectionNoticeNewResp> resps = JSONObject.parseArray(
                        jsonObject.getJSONArray("data").toJSONString(), QueryInspectionNoticeNewResp.class);
                //出参转换结束
                List<QueryInspectionNoticeResp> list = this.transFormResqD7(resps);
                result.setData(list);
            } else {
                result.setCode(ResultCode.ERROR);
                result.setMessage(jsonObject.getString("message"));
            }
        } catch (JSONException e) {
            e.printStackTrace();
            result.setCode(ResultCode.ERROR);
            result.setMessage(jsonObject.getString("message"));
        }
        return result;
    }

    //入参转化
    public QueryInspectionExtraFeeNewReq transFormReq(QueryInspectionNoticeReq req){
        QueryInspectionExtraFeeNewReq inspectionExtraFeeNewReq = new QueryInspectionExtraFeeNewReq();
        inspectionExtraFeeNewReq.setVisitOrganization(req.getOrganizationId());
        List<InspectionItemNew> Itemlists = new ArrayList<>();
        if(CommonUtils.isNotEmpty(req.getInspectionItemList())){
            for (InspectionItem inspectionItem:req.getInspectionItemList()) {
                InspectionItemNew inspectionItemNew = new InspectionItemNew();
                inspectionItemNew.setItemCode(inspectionItem.getInspectionItemId());
                inspectionItemNew.setItemName(inspectionItem.getInspectionItemName());
                inspectionItemNew.setRequestId(inspectionItem.getApplicationNo());
                inspectionItemNew.setSampleTypeCode(inspectionItem.getSpecimenTypeId());
                inspectionItemNew.setSampleTypeName(inspectionItem.getSpecimenTypeName());
                inspectionItemNew.setItemCount(inspectionItem.getNumber());
                Itemlists.add(inspectionItemNew);
            }
        }

        QueryInspectionExtraFeeNewReq.Itemlists itemlists = new QueryInspectionExtraFeeNewReq.Itemlists();
        itemlists.setItemlist(Itemlists);
        inspectionExtraFeeNewReq.setItemlists(itemlists);

        return inspectionExtraFeeNewReq;
    }


    //出参转化
    public List<QueryInspectionNoticeResp> transFormResqD7(List<QueryInspectionNoticeNewResp> list){
        List<QueryInspectionNoticeResp> resps = new ArrayList<>();
        if(CommonUtils.isNotEmpty(list)){
            for (QueryInspectionNoticeNewResp resp:list) {
                QueryInspectionNoticeResp querySampleTypeResp = new QueryInspectionNoticeResp();
                querySampleTypeResp.setInspectionItems(resp.getExaminationPurpose());
                querySampleTypeResp.setSamplingAttention(resp.getRequestNote());
                querySampleTypeResp.setSamplingPlace(resp.getSampleCollectPlace());
                resps.add(querySampleTypeResp);
            }
        }
        return resps;
    }


//
//    /**
//     * 获取检验申请单类别和项目
//     * @param queryInspectionItemListReq
//     * @return
//     */
//    @Override
//    public BaseResponse<List<QueryInspectionItemListResp>> queryInspectionItemListXML(QueryInspectionItemListReq queryInspectionItemListReq) {
//        log.info("queryInspectionItemList-入参=>>>" + queryInspectionItemListReq.toString() + "=====");
//        BaseResponse baseResponse = new BaseResponse();
//        QueryInspectionItemListNewReq queryInspectionItemListNewReq =   this.transFormReq(queryInspectionItemListReq);
//        //转化为xml
//        String xml = JAXBUtils.object2Xml(QueryInspectionItemListNewReq.class,queryInspectionItemListNewReq);
//        //请求
//        try {
//            baseResponse =  CheckAppointmentUtil.postFromPlatform(url, InspectionEmum.LabRequestQueryItems.getCode(),getheader(),xml);
//        } catch (XMLStreamException e) {
//            return baseResponse;
//        } catch (IOException e) {
//            return baseResponse;
//        }
//        List<QueryInspectionItemListNewResp> resps = new ArrayList<>();
//        if(ResultCode.SUCCESS == baseResponse.getCode()){
//            String req_xml = baseResponse.getData().toString();
//            LabRequestQueryItemsResponse list = JAXBUtils.xml2Object(req_xml,LabRequestQueryItemsResponse.class);
//            resps = list.getDataLists().getDataList();
////            resps.addAll(list.getDataLists().getDataList());
//        }
//
//        List<QueryInspectionItemListResp>  list = this.transFormResqD0(resps);
//        return BaseRespUtil.setResultSuccess(list);
//    }
//
//    /**
//     * 获取检验申请单子项目明细
//     * @param queryInspectionItemDtailReq
//     * @return
//     */
//    @Override
//    public BaseResponse<List<QueryInspectionItemDtailResp>> queryInspectionItemDtailXML(QueryInspectionItemDtailReq queryInspectionItemDtailReq) {
//        log.info("queryInspectionItemDtail-入参=>>>" + queryInspectionItemDtailReq.toString() + "=====");
//        BaseResponse baseResponse = new BaseResponse();
//        QueryInspectionItemDtailNewReq req1 = this.transFormReq(queryInspectionItemDtailReq);
//        //转化为xml
//        String xml = JAXBUtils.object2Xml(QueryInspectionItemDtailNewReq.class,req1);
//        //请求
//        try {
//            baseResponse =  CheckAppointmentUtil.postFromPlatform(url, InspectionEmum.LabRequestQueryItemDtail.getCode(),getheader(),xml);
//        } catch (XMLStreamException e) {
//            return baseResponse;
//        } catch (IOException e) {
//            return baseResponse;
//        }
//
//        //转化为对象
//        List<QueryInspectionItemDtailNewResp> resps = new ArrayList<>();
//        if(ResultCode.SUCCESS == baseResponse.getCode()){
//            String json = baseResponse.getData().toString();
//            LabRequestQueryItemDtailResponse list =   JAXBUtils.xml2Object(json, LabRequestQueryItemDtailResponse.class);
//            resps=list.getItems().getItem();
//        }
//
//        List<QueryInspectionItemDtailResp>  list = this.transFormResqD1(resps);
//        return BaseRespUtil.setResultSuccess(list);
//    }
//
//    /**
//     * 3、获取样本类型
//     * @param request
//     * @return
//     */
//    @Override
//    public BaseResponse<List<QuerySampleTypeResp>> querySampleTypeXML(QuerySampleTypeReq request) {
//        log.info("querySampleType-入参=>>>" + request.toString() + "=====");
//        BaseResponse baseResponse = new BaseResponse();
//        QueryInspectionItemDtailNewReq req = this.transFormReq(request);
//        //转化为xml
//        String xml =  JAXBUtils.object2Xml(QueryInspectionItemDtailNewReq.class,req);
//        //请求
//        try {
//            baseResponse =  CheckAppointmentUtil.postFromPlatform(url, InspectionEmum.LabRequestQuerySampletype.getCode(),getheader(),xml);
//        } catch (XMLStreamException e) {
//            return baseResponse;
//        } catch (IOException e) {
//            return baseResponse;
//        }
//        //转化为对象
//        List<QuerySampleTypeNewResp> resps = new ArrayList<>();
//        if(ResultCode.SUCCESS == baseResponse.getCode()){
//            String json = baseResponse.getData().toString();
//            SampleTypeNewResponse list =  JAXBUtils.xml2Object(json, SampleTypeNewResponse.class);
//            resps.addAll(list.getResponse().getDatalists().getDatalist());
//        }
//        List<QuerySampleTypeResp> querySampleTypeResps = this.transFormResqD2(resps);
//        return BaseRespUtil.setResultSuccess(querySampleTypeResps);
//    }
//
//
//    /**
//     * @Description: 获得检验申请单号
//     * @Author: zhaorb
//     * @Date: 2020/8/4 14:05
//     **/
//    @Override
//    public BaseResponse<List<ApplyNoResponse>> queryInspectionApplyNoXML(ApplyNoRequest request) {
//        BaseResponse<List<ApplyNoResponse>> response = new BaseResponse<>();
//        List<ApplyNoResponse> result = new ArrayList<>();
//        BaseResponse baseResponse = new BaseResponse();
//        ApplyNoNewRequest applyNoNewRequest = this.transFormReq(request);
//        //转化为xml
//        String xml =  JAXBUtils.object2Xml(ApplyNoNewRequest.class,applyNoNewRequest);
//        //请求
//        try {
//            baseResponse =  CheckAppointmentUtil.postFromPlatform(url, InspectionEmum.LabRequestGetRequestId.getCode(),getheader(),xml);
//        } catch (XMLStreamException e) {
//            return baseResponse;
//        } catch (IOException e) {
//            return baseResponse;
//        }
//        //转化为对象
//        List<ApplyNoNewResponse> resp = new ArrayList<>();
//        if(ResultCode.SUCCESS == baseResponse.getCode()){
//            String json = baseResponse.getData().toString();
//            LabRequestGetRequestIdResponse list =  JAXBUtils.xml2Object(json, LabRequestGetRequestIdResponse.class);
//            resp= list.getDatalists().getDatalist();
//        }
//        List<ApplyNoResponse> responses = this.transFormResqD3(resp);
//        response.setData(responses);
//        return response;
//    }
//
//    /**
//     * 提交申请单
//     * @param saveInspectionInfoReq
//     * @return
//     */
//    @Override
//    public BaseResponse<SaveInspectionInfoResp> saveInspectionInfoXML(SaveInspectionInfoReq saveInspectionInfoReq) {
//        SaveInspectionInfoNewReq saveInspectionInfoNewReq = this.transFormReq(saveInspectionInfoReq);
//        BaseResponse<SaveInspectionInfoResp> response = new BaseResponse<>();
//        BaseResponse baseResponse = new BaseResponse();
//        //转化为xml
//        String xml =  JAXBUtils.object2Xml(SaveInspectionInfoNewReq.class,saveInspectionInfoNewReq);
//        //请求
//        try {
//            baseResponse =  CheckAppointmentUtil.postFromPlatform(url, InspectionEmum.LabRequestSubmit.getCode(),getheader(),xml);
//        } catch (XMLStreamException e) {
//            return baseResponse;
//        } catch (IOException e) {
//            return baseResponse;
//        }
//        //转化为对象
//        SaveInspectionInfoNewResp resp = new SaveInspectionInfoNewResp();
//        if(ResultCode.SUCCESS == baseResponse.getCode()){
//            String json = baseResponse.getData().toString();
//            LabRequestSubmitResponse list =  JAXBUtils.xml2Object(json, LabRequestSubmitResponse.class);
//            resp = list.getResponse();
//        }
//        SaveInspectionInfoResp saveInspectionInfoResp = this.transFormResqD4(resp);
//        response.setData(saveInspectionInfoResp);
//        return response;
//    }
//
//    /**
//     * 7、撤销申请单
//     * @param request
//     * @return
//     */
//    @Override
//    public BaseResponse cancelInspectionItemXML(CancelInspectionItemReq request) {
//        log.info("=cancelInspectionItem-入参=>>>" + request.toString() + "=====");
//        BaseResponse baseResponse = new BaseResponse();
//        CancelInspectionItemNewReq cancelInspectionItemNewReq = this.transFormReq(request);
//        //转化为xml
//        String xml =  JAXBUtils.object2Xml(CancelInspectionItemNewReq.class,cancelInspectionItemNewReq);
//        //请求
//        try {
//            baseResponse =  CheckAppointmentUtil.postFromPlatform(url, InspectionEmum.LabRequestCancel.getCode(),getheader(),xml);
//        } catch (XMLStreamException e) {
//            return baseResponse;
//        } catch (IOException e) {
//            return baseResponse;
//        }
//        if(ResultCode.SUCCESS == baseResponse.getCode()){
//            String json = baseResponse.getData().toString();
//            CancelRequestIdResponse list =  JAXBUtils.xml2Object(json, CancelRequestIdResponse.class);
//            MsgHeader msgHeader = list.getMsgHeader();
//            if(CommonUtils.isNotEmpty(msgHeader)){
//                if(!"true".equals(msgHeader.getStatus())){
//                    baseResponse.setCode(-1);
//                    baseResponse.setMessage(msgHeader.getDetail());
//                    return baseResponse;
//                }
//            }
//        }
//        return baseResponse;
//    }
//
//    /**
//     * 5、获取申请单项目附加费用
//     * @param request
//     * @return
//     */
//    @Override
//    public BaseResponse<QueryInspectionExtraFeeResp> queryInspectionExtraFeeXML(QueryInspectionExtraFeeReq request) {
//        log.info("=queryInspectionExtraFee-入参=>>>" + request.toString() + "=====");
//        BaseResponse<QueryInspectionExtraFeeResp> result = new BaseResponse();
//        QueryInspectionExtraFeeNewReq req = this.transFormReq(request);
//        BaseResponse baseResponse = new BaseResponse();
//        //转化为xml
//        String xml =  JAXBUtils.object2Xml(QueryInspectionExtraFeeNewReq.class,req);
//
//        try {
//            baseResponse =  CheckAppointmentUtil.postFromPlatform(url, InspectionEmum.LabRequestGetSurcharge.getCode(),getheader(),xml);
//        } catch (XMLStreamException e) {
//            return baseResponse;
//        } catch (IOException e) {
//            return baseResponse;
//        }
//
//        //出参转换开始
//        QueryInspectionExtraFeeNewResp resp = null;
//        if(ResultCode.SUCCESS == baseResponse.getCode()){
//            String json = baseResponse.getData().toString();
//            LabRequestGetSurchargeResponse list =   JAXBUtils.xml2Object(json, LabRequestGetSurchargeResponse.class);
//            resp =list.getItemlists();
//        }
//        //出参转换结束
//        QueryInspectionExtraFeeResp resps = this.transFormResqD6(resp);
//        result.setData(resps);
//        return result;
//    }
//
//    /**
//     * 6、获取申请单注意事项
//     * @param request
//     * @return
//     */
//    @Override
//    public BaseResponse<List<QueryInspectionNoticeResp>> queryInspectionNoticeXML(QueryInspectionNoticeReq request) {
//        log.info("=queryInspectionNotice-入参=>>>" + request.toString() + "=====");
//        BaseResponse<List<QueryInspectionNoticeResp>> result = new BaseResponse();
//        QueryInspectionExtraFeeNewReq req = this.transFormReq(request);
//        BaseResponse baseResponse = new BaseResponse();
//        //转化为xml
//        String xml =  JAXBUtils.object2Xml(QueryInspectionExtraFeeNewReq.class,req);
//        try {
//            baseResponse =  CheckAppointmentUtil.postFromPlatform(url, InspectionEmum.LabRequestGetCollectNote.getCode(),getheader(),xml);
//        } catch (XMLStreamException e) {
//            return baseResponse;
//        } catch (IOException e) {
//            return baseResponse;
//        }
//
//
//        //出参转换开始
//        List<QueryInspectionNoticeNewResp> resps = new ArrayList<>();
//        if(ResultCode.SUCCESS == baseResponse.getCode()){
//            String json = baseResponse.getData().toString();
//            LabRequestGetCollectNoteResponse list =  JAXBUtils.xml2Object(json, LabRequestGetCollectNoteResponse.class);
//            resps = list.getDatalists().getDatalist();
//        }
//        //出参转换结束
//        List<QueryInspectionNoticeResp> list = this.transFormResqD7(resps);
//        result.setData(list);
//        return result;
//    }
//
//
//
//    public static void main(String[] args) {
////        String Msgheader = "<MsgHeader><Sender>HIS</Sender><MsgType>ODS_1001</MsgType><MsgVersion>3.0</MsgVersion></MsgHeader>";
////        QueryInspectionItemDtailNewReq req = new QueryInspectionItemDtailNewReq();
////        req.setVisitOrganization("330102001");
////        req.setItemCode("");
////        //转化为xml
////        String xml =  JAXBUtils.object2Xml(QueryInspectionItemDtailNewReq.class,req);
////        System.out.println("xml======   "+xml);
////        //请求
////        BaseResponse result = null;
////        try {
////             result =  CheckAppointmentUtil.postFromPlatform("http://10.8.3.125:8070/labPlatInterface/appServlet","LabRequestQuerySampletype",Msgheader,xml);
////        } catch (XMLStreamException e) {
////            e.printStackTrace();
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
////       System.out.println(result);
////
////
////        String json = result.getData().toString();
////        SampleTypeNewResponse list =  JSON.parseObject(json, SampleTypeNewResponse.class);
////        System.out.println("最终答案"+list.getResponse().getDatalists().getDatalist().get(0).getSampleTypeCode());
////        QueryInspectionExtraFeeNewReq req = new QueryInspectionExtraFeeNewReq();
////        req.setVisitOrganization("330102001");
////        QueryInspectionExtraFeeNewReq.Itemlists itemlists = new QueryInspectionExtraFeeNewReq.Itemlists();
////        InspectionItemNew inspectionItemNew = new InspectionItemNew();
////        inspectionItemNew.setItemCount(new BigDecimal("0.1"));
////        inspectionItemNew.setSampleTypeName("11");
////        inspectionItemNew.setSampleTypeCode("11");
////        inspectionItemNew.setRequestId("11");
////        inspectionItemNew.setItemName("1");
////        inspectionItemNew.setItemCode("1");
////        List<InspectionItemNew> inspectionItemNews = new ArrayList<>();
////        inspectionItemNews.add(inspectionItemNew);
////        itemlists.setItemlist(inspectionItemNews);
////        req.setItemlists(itemlists);
//////        //转化为xml
////
////                String xml =  JAXBUtils.object2Xml(QueryInspectionExtraFeeNewReq.class,req);
////    System.out.println(xml);
////        String json = "{\"DataLists\":{\"DataList\":[{\"ItemTypeCode\":1,\"ItemTypeName\":\"生化系列\",\"Items\":{\"Item\":[{\"ItemCode\":6709,\"ItemPrice\":2,\"IsEmergency\":0,\"ItemName\":\"白细胞计数(WBC)\",\"ItemCount\":1,\"SampleTypeCode\":0,\"SampleTypeName\":\"末段尿\",\"ComposeType\":0,\"InputCode\":\"BXBJS\"},{\"ItemCode\":2008,\"ItemPrice\":139.5,\"IsEmergency\":0,\"ItemName\":\"生化全套\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"SHQT\"},{\"ItemCode\":12466,\"ItemPrice\":98,\"IsEmergency\":0,\"ItemName\":\"常规项目\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"CGXM\"}]}},{\"ItemTypeCode\":2,\"ItemTypeName\":\"免疫系列\",\"Items\":{\"Item\":[{\"ItemCode\":2009,\"ItemPrice\":189,\"IsEmergency\":0,\"ItemName\":\"甲肝+丙肝\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"JGBG\"},{\"ItemCode\":2010,\"ItemPrice\":470,\"IsEmergency\":0,\"ItemName\":\"单纯疱疹I+II\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"DCPZII\"}]}},{\"ItemTypeCode\":3,\"ItemTypeName\":\"临检系列\",\"Items\":{\"Item\":{\"ItemCode\":1242,\"ItemPrice\":320,\"IsEmergency\":0,\"ItemName\":\"血常规\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XCG\"}}},{\"ItemTypeCode\":4,\"ItemTypeName\":\"急诊项目\",\"Items\":\"\"},{\"ItemTypeCode\":5,\"ItemTypeName\":\"微生物\",\"Items\":{\"Item\":[{\"ItemCode\":1206,\"ItemPrice\":30,\"IsEmergency\":0,\"ItemName\":\"痰培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"K\",\"SampleTypeName\":\"痰\",\"ComposeType\":0,\"InputCode\":\"ZJPYJJD\"},{\"ItemCode\":1235,\"ItemPrice\":38,\"IsEmergency\":0,\"ItemName\":\"结核检测\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"JHJC\"},{\"ItemCode\":1236,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"血需氧+厌氧菌培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"XXYYYJ\"},{\"ItemCode\":1244,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"血液培养1\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"XYPY1\"},{\"ItemCode\":1245,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"尿培养\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"NPY\"},{\"ItemCode\":1246,\"ItemPrice\":125,\"IsEmergency\":0,\"ItemName\":\"血培养\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XPY\"},{\"ItemCode\":1247,\"ItemPrice\":25,\"IsEmergency\":0,\"ItemName\":\"血厌氧培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XYYPYJ\"}]}}]},\"MsgHeader\":{\"Sender\":\"HIP\",\"Status\":true,\"ReturnCount\":5,\"MsgType\":\"ODS_2140\",\"MsgVersion\":3,\"Detail\":\"查询成功\",\"ErrCode\":\"\"}}";
////        LabRequestQueryItemsResponse list =  JSON.parseObject(json, LabRequestQueryItemsResponse.class);
////        System.out.println(list.getDatalists().toString());
////        String json2 = "[{\"ItemTypeCode\":1,\"ItemTypeName\":\"生化系列\",\"Items\":{\"Item\":[{\"ItemCode\":6709,\"ItemPrice\":2,\"IsEmergency\":0,\"ItemName\":\"白细胞计数(WBC)\",\"ItemCount\":1,\"SampleTypeCode\":0,\"SampleTypeName\":\"末段尿\",\"ComposeType\":0,\"InputCode\":\"BXBJS\"},{\"ItemCode\":2008,\"ItemPrice\":139.5,\"IsEmergency\":0,\"ItemName\":\"生化全套\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"SHQT\"},{\"ItemCode\":12466,\"ItemPrice\":98,\"IsEmergency\":0,\"ItemName\":\"常规项目\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"CGXM\"}]}},{\"ItemTypeCode\":2,\"ItemTypeName\":\"免疫系列\",\"Items\":{\"Item\":[{\"ItemCode\":2009,\"ItemPrice\":189,\"IsEmergency\":0,\"ItemName\":\"甲肝+丙肝\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"JGBG\"},{\"ItemCode\":2010,\"ItemPrice\":470,\"IsEmergency\":0,\"ItemName\":\"单纯疱疹I+II\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"DCPZII\"}]}},{\"ItemTypeCode\":3,\"ItemTypeName\":\"临检系列\",\"Items\":{\"Item\":{\"ItemCode\":1242,\"ItemPrice\":320,\"IsEmergency\":0,\"ItemName\":\"血常规\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XCG\"}}},{\"ItemTypeCode\":4,\"ItemTypeName\":\"急诊项目\",\"Items\":\"\"},{\"ItemTypeCode\":5,\"ItemTypeName\":\"微生物\",\"Items\":{\"Item\":[{\"ItemCode\":1206,\"ItemPrice\":30,\"IsEmergency\":0,\"ItemName\":\"痰培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"K\",\"SampleTypeName\":\"痰\",\"ComposeType\":0,\"InputCode\":\"ZJPYJJD\"},{\"ItemCode\":1235,\"ItemPrice\":38,\"IsEmergency\":0,\"ItemName\":\"结核检测\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"JHJC\"},{\"ItemCode\":1236,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"血需氧+厌氧菌培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"XXYYYJ\"},{\"ItemCode\":1244,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"血液培养1\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"XYPY1\"},{\"ItemCode\":1245,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"尿培养\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"NPY\"},{\"ItemCode\":1246,\"ItemPrice\":125,\"IsEmergency\":0,\"ItemName\":\"血培养\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XPY\"},{\"ItemCode\":1247,\"ItemPrice\":25,\"IsEmergency\":0,\"ItemName\":\"血厌氧培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XYYPYJ\"}]}}]";
////        List<QueryInspectionItemListNewResp> resp = JSON.parseArray(json2, QueryInspectionItemListNewResp.class);
////        System.out.println(resp.get(0).getItems());
////        String json = "{\n" +
////                "    \"patientId\":\"2549\",\n" +
////                "    \"sourcePatientIdType\":\"1\",\n" +
////                "    \"authorOrganization\":\"1\",\n" +
////                "    \"patientName\":\"陈默默\",\n" +
////                "    \"sex\":\"1\",\n" +
////                "    \"birthday\":\"2004-06-12 00:00:00\",\n" +
////                "    \"cardType\":\"2\",\n" +
////                "    \"cardNumber\":\"460035200406127637\",\n" +
////                "    \"telephone\":\"\",\n" +
////                "    \"address\":\"\",\n" +
////                "    \n" +
////                "    \"patientHospitalNumber\":\"\",\n" +
////                "    \"organizationId\":\"1\",\n" +
////                "    \"source\":\"1\",\n" +
////                "    \"patientMedicalCardType\":\"2\",\n" +
////                "    \"patientMedicalCardNumber\":\"1908000784\",\n" +
////                "    \"inHospitalRecordCode\":\"1477\",\n" +
////                "    \"PatientProperties\":\"1000\",\n" +
////                "    \"onlineEmergencyNumber\":\"\",\n" +
////                "    \"registeredSerialNo\":\"\",\n" +
////                "    \"applicationlist\":{\n" +
////                "        \"applicationNo\":\"1062\",\n" +
////                "        \"isNeonatus\":\"0\",\n" +
////                "        \"age\":16,\n" +
////                "        \"inpatientWardId\":\"\",\n" +
////                "        \"inpatientWardName\":\"\",\n" +
////                "        \"bedNumber\":\"\",\n" +
////                "        \"isEmergency\":\"0\",\n" +
////                "        \"applyTime\":\"2020-09-22 11:05:18\",\n" +
////                "        \"effectiveTimeLow\":\"\",\n" +
////                "        \"effectiveTimeHigh\":\"\",\n" +
////                "        \"applyDoctorId\":\"2000004\",\n" +
////                "        \"applyDoctorName\":\"测试\",\n" +
////                "        \"applyDepartmentId\":\"1021\",\n" +
////                "        \"applyDepartmentName\":\"检验科\",\n" +
////                "        \"departmentId\":\"\",\n" +
////                "        \"departmentName\":\"\",\n" +
////                "        \"requestCheckerId\":\"\",\n" +
////                "        \"requestCheckerName\":\"\",\n" +
////                "        \"requestCheckTime\":\"\",\n" +
////                "        \"requestStatus\":2,\n" +
////                "        \"diagnosisReqList\":[\n" +
////                "            {\n" +
////                "                \"diseasesId\":\"\",\n" +
////                "                \"diseasesCode\":\"\",\n" +
////                "                \"diagnosisType\":\"1\",\n" +
////                "                \"diseasesName\":\"感冒\"\n" +
////                "            },\n" +
////                "            {\n" +
////                "                \"diseasesId\":\"\",\n" +
////                "                \"diseasesCode\":\"\",\n" +
////                "                \"diagnosisType\":\"2\",\n" +
////                "                \"diseasesName\":\"发烧\"\n" +
////                "            }\n" +
////                "        ],\n" +
////                "        \"inspectionItemDetailList\":[\n" +
////                "            {\n" +
////                "                \"expenseId\":\"4300\",\n" +
////                "                \"inspectionItemId\":\"1242\",\n" +
////                "                \"inspectionItemName\":\"血常规\",\n" +
////                "                \"specimenTypeId\":\"C\",\n" +
////                "                \"specimenTypeName\":\"血液\",\n" +
////                "                \"number\":\"1\",\n" +
////                "                \"price\":\"15\",\n" +
////                "                \"ItemCost\":\"15\",\n" +
////                "                \"feeStatus\":\"0\",\n" +
////                "                \"isFree\":\"0\",\n" +
////                "                \"executeDepartmentId\":\"3087\",\n" +
////                "                \"executeDepartmentName\":\"临检室\",\n" +
////                "                \"feeType\":\"1\",\n" +
////                "                \"itemList\":[\n" +
////                "                    {\n" +
////                "                        \"inspectionItemDetailId\":\"6\",\n" +
////                "                        \"inspectionItemDetailName\":\"25羟基维生素D测定-色谱法（艾迪康）\",\n" +
////                "                        \"jlxh\":\"6422\",\n" +
////                "                        \"itemId\":\"12394\",\n" +
////                "                        \"itemName\":\"25羟基维生素D测定-色谱法（艾迪康）\",\n" +
////                "                        \"number\":\"1\",\n" +
////                "                        \"price\":\"170\"\n" +
////                "                    },\n" +
////                "                    {\n" +
////                "                        \"inspectionItemDetailId\":\"24\",\n" +
////                "                        \"inspectionItemDetailName\":\"EB病毒核酸定量(艾迪康）\",\n" +
////                "                        \"jlxh\":\"6423\",\n" +
////                "                        \"itemId\":\"12391\",\n" +
////                "                        \"itemName\":\"EB病毒核酸定量(艾迪康）\",\n" +
////                "                        \"number\":\"1\",\n" +
////                "                        \"price\":\"150\"\n" +
////                "                    }\n" +
////                "                ]\n" +
////                "            }\n" +
////                "        ]\n" +
////                "    }\n" +
////                "}";
////
////        SaveInspectionInfoNewReq saveInspectionInfoReq =   JSONObject.parseObject(json,SaveInspectionInfoNewReq.class);
////        //转化为xml
////        String xml =  JAXBUtils.object2Xml(SaveInspectionInfoNewReq.class,saveInspectionInfoReq);
////        System.out.println(xml);
//
//
//
//        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BSXml><MsgHeader><Sender>HIP</Sender><MsgType>ODS_2140</MsgType><MsgVersion>3.0</MsgVersion><Status>true</Status><ErrCode></ErrCode><Detail>查询成功</Detail><ReturnCount>1</ReturnCount></MsgHeader><Response><VisitOrganization>1</VisitOrganization><VisitOrganizationName>南滨街道卫生院</VisitOrganizationName><SourcePatientId>2549</SourcePatientId><Name>陈默默</Name><Sex>1</Sex><IdCardCode>2</IdCardCode><IdCard>460035200406127637</IdCard><MedicalCardType>2</MedicalCardType><MedicalCardId>1908000784</MedicalCardId><VisitId>1477</VisitId><Dept>1022</Dept><DeptName>内科</DeptName><RequestDoctor>2000004</RequestDoctor><RequestDoctorName>测试</RequestDoctorName><RequestDept>1021</RequestDept><RequestDeptName>检验科</RequestDeptName><LabRequest><RequestId>1062</RequestId><RequestStatus>2</RequestStatus><IsEmergency>0</IsEmergency><Items><Item><AdviceExpenseId>4300</AdviceExpenseId><ItemCode>1242</ItemCode><ItemName>血常规</ItemName><SampleTypeCode>C</SampleTypeCode><SampleTypeName>血液</SampleTypeName><ItemPrice>15</ItemPrice><ItemCount>1</ItemCount><ItemCost>15</ItemCost><FeeStatus>0</FeeStatus><CostFreeSign>0</CostFreeSign><RequestNote></RequestNote><InvoiceNo></InvoiceNo><ExamExecuteDept>3087</ExamExecuteDept><ExamExecuteDeptName>临检室</ExamExecuteDeptName><ExamMethodCode></ExamMethodCode><ExamMethodName></ExamMethodName><FeeType>0</FeeType><Childitems><Childitem><ChildItemCode>6</ChildItemCode><ChildItemName>25羟基维生素D测定-色谱法（艾迪康）</ChildItemName><AdviceExpenseDetailId>6422</AdviceExpenseDetailId><CostId>12394</CostId><CostName>25羟基维生素D测定-色谱法（艾迪康）</CostName><CostNumber>1</CostNumber><CostPrice>170</CostPrice><CostUnit></CostUnit><DetailCost>170.0</DetailCost></Childitem><Childitem><ChildItemCode>24</ChildItemCode><ChildItemName>EB病毒核酸定量(艾迪康）</ChildItemName><AdviceExpenseDetailId>6423</AdviceExpenseDetailId><CostId>12391</CostId><CostName>EB病毒核酸定量(艾迪康）</CostName><CostNumber>1</CostNumber><CostPrice>150</CostPrice><CostUnit></CostUnit><DetailCost>150.0</DetailCost></Childitem></Childitems></Item></Items></LabRequest></Response></BSXml>";
//
//        LabRequestSubmitResponse json12 = JAXBUtils.xml2Object(xml,LabRequestSubmitResponse.class);
//        System.out.println(json12);
//    }
//
//
//
//
//
//
//    public  String getheader(){
//       String Msgheader = "<MsgHeader><Sender>HIS</Sender><MsgType>ODS_1001</MsgType><MsgVersion>3.0</MsgVersion></MsgHeader>";
//        return Msgheader;
//    }

}

